﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

//using PowerCreator.LMS.Logic.Common;
//using PowerCreator.LMS.Logic.ProjectManager;
//using PowerCreator.LMS.Model.Entity;
//using PowerCreator.LMS.Logic.Fpager;
//using PowerCreator.LMS.Logic.CourseManager;
//using PowerCreator.LMS.Logic.QuestionManager;
//using PowerCreator.LMS.Logic.PaperManager;
using System.Text;

public partial class sysadmin_CountManager_UserProjectScheduleInfo : PowerCreator.LMS.Web.Base.BasePage
{
    //ManagerClassInfo objClassInfoLogic = new ManagerClassInfo();
    //ManagerProjectResource objprojectresourcelogic = new ManagerProjectResource();
    //ManagerProjectSchedule objprojectschedulelogic = new ManagerProjectSchedule();
    //ManagerProjectInfo projectManager = new ManagerProjectInfo();
    //ManagerPaperInfo paperManager = new ManagerPaperInfo();
    //ManagerCourseInfo courseManager = new ManagerCourseInfo();

    const string TABLE_BEGIN = "<table width=\"100%\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\" class=\"mainList\" >";
    const string TABLE_END = "</table>";
    const string TABLE_TR_BEGIN = "<tr>";
    const string TBALE_TR_END = "</tr>";
    const string TBALE_TD_BEGIN = "<td>";
    const string TBALE_TD_END = "</td>";
    const string TBALE_TH_BEGIN = "<th nowrap=\"nowrap\" >";
    const string TBALE_TH_END = "</th>";
    const string TD_STARTING_BEGIN = "<td><img src=\"../../images/go.GIF\" width=\"24\" height=\"24\"><span class=\"STYLE6\">";
    const string TD_STARTING_END = "</span></td>";
    const string TD_END_BEGIN = "<td class=\"imgok\" style=\"padding-left:30px;\">";
    const string TD_END_END = "</span></td>";
    const string TD_UNSTART_BEGIN = "<td><img src=\"../../images/start.GIF\" width=\"24\" height=\"24\"><span class=\"STYLE7\">";
    const string TD_UNSTART_END = "</span></td>";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {         
            
            //string ProjectID = Base64.Decode(Request.QueryString["p"].ToString());
            //ViewState.Add("ProjectID", ProjectID);
            //ProjectInfo info = new ProjectInfo();
            //info = projectManager.Load(int.Parse(ProjectID));

            //ViewState.Add("ProjectName",info.ProjectName);
            //lab_ProjectName.Text = info.ProjectName;

            //BandClassName();

            //string search = GetSearch();
            //BinderPager(search);
            //BinderGV(search, 1);

        }
    }
    private void BandClassName()
    {
        //string search = string.Format("ProjectID={0}", ViewState["ProjectID"].ToString());
        //dpdlst_ClassName.DataSource = objClassInfoLogic.Query(search);
        //dpdlst_ClassName.DataTextField = "ClassName";
        //dpdlst_ClassName.DataValueField = "ClassID";
        //dpdlst_ClassName.DataBind();
    }
    private string GetSearch()
    {
        string search = string.Empty;
        if (!string.IsNullOrEmpty(txtUserName.Text.Trim()))
        {
            search = string.Format(" and UserName like '%{0}%'", txtUserName.Text);
        }


        return search;
    }
    private void BinderPager(string search)
    {
    //    AspNetPager1.RecordCount = objprojectschedulelogic.SearchUserProjectScheduleCount(int.Parse(ViewState["ProjectID"].ToString()), int.Parse(dpdlst_ClassName.SelectedValue), search);
    //    AspNetPager1.PageSize = FBasePage.PageSize();
    }
    private string GetResourceName(string typeid, string resourceid)
    {
        string resourceName = string.Empty;
        if (typeid == "0")
        {
            //DataTable dt_Course=courseManager.Query("CourseID=" + resourceid);
            //if (dt_Course.Rows.Count == 0)
            //{
            //    resourceName = "该课程已删除";
            //}
            //else
            //{
            //    resourceName = dt_Course.Rows[0]["CourseName"].ToString(); 
            //}
           // resourceName = courseManager.Load(int.Parse(resourceid)).CourseName;
        }
        else if (typeid == "1")
        {
            //DataTable dt_Paper = paperManager.Query("PaperID="+ resourceid);
            //if (dt_Paper.Rows.Count == 0)
            //{
            //    resourceName = "该试卷已删除";
            //}
            //else
            //{
            //    resourceName = dt_Paper.Rows[0]["PaperName"].ToString();
            //}
            //resourceName = paperManager.Load(int.Parse(resourceid)).PaperName;
        }
        else
        {
            resourceName = "未知资源名称";
        }
        return resourceName;
    }
    private void BinderGV(string search, int pageIndex)
    {
        //DataTable dt_UserProjectSchedule = new DataTable();
        ////获取用户培训进度
        //dt_UserProjectSchedule = objprojectschedulelogic.SearchUserProjectSchedule(int.Parse(ViewState["ProjectID"].ToString()), int.Parse(dpdlst_ClassName.SelectedValue), search, pageIndex, FBasePage.PageSize());
        //if (dt_UserProjectSchedule.Rows.Count == 0)
        //{
        //    lab_table.Text = "没有数据";
        //    return;
        //}

        //StringBuilder str_table = new StringBuilder();
        //DataTable dt_MustResource = new DataTable();
        //DataTable dt_UnMustResource = new DataTable();
        ////获取必修资源
        //dt_MustResource = objprojectresourcelogic.Query("ProjectID=" + ViewState["ProjectID"].ToString() + " and OpenMode=0 ");
        ////获取选修资源
        //dt_UnMustResource = objprojectresourcelogic.Query("ProjectID=" + ViewState["ProjectID"].ToString() + " and OpenMode=1 ");

        //str_table.Append(TABLE_BEGIN);
        //str_table.Append(TABLE_TR_BEGIN);

        //str_table.Append(TBALE_TH_BEGIN);
        //str_table.Append("班级名称");
        //str_table.Append(TBALE_TH_END);

        //str_table.Append(TBALE_TH_BEGIN);
        //str_table.Append("帐户");
        //str_table.Append(TBALE_TH_END);

        //str_table.Append(TBALE_TH_BEGIN);
        //str_table.Append("真实姓名");
        //str_table.Append(TBALE_TH_END);
        
        //str_table.Append(TBALE_TH_BEGIN);
        //str_table.Append("用户ID");
        //str_table.Append(TBALE_TH_END);

        //for (int i = 0; i < dt_MustResource.Rows.Count; i++)
        //{
        //    str_table.Append(TBALE_TH_BEGIN);
        //    str_table.Append(GetResourceName(dt_MustResource.Rows[i]["TypeID"].ToString(), dt_MustResource.Rows[i]["ResourceID"].ToString())+"(必修)");

        //    //str_table.Append(dt_MustResource.Rows[i]["ResourceName"].ToString() + "(必修)");
        //    str_table.Append(TBALE_TH_END);
        //}
        //for (int i = 0; i < dt_UnMustResource.Rows.Count; i++)
        //{
        //    str_table.Append(TBALE_TH_BEGIN);
        //    str_table.Append(GetResourceName(dt_MustResource.Rows[i]["TypeID"].ToString(), dt_MustResource.Rows[i]["ResourceID"].ToString()) + "(选修)");
        //    //str_table.Append(dt_UnMustResource.Rows[i]["ResourceName"].ToString() + "(选修)");
        //    str_table.Append(TBALE_TH_END);
        //}
        ////合并必修选修资源
        //dt_MustResource.Merge(dt_UnMustResource);

        ////重新排列资源顺序
        //for (int j = 0; j < dt_MustResource.Rows.Count; j++)
        //{
        //    for (int i = 5; i < dt_UserProjectSchedule.Columns.Count; i++)
        //    {
        //        if (dt_MustResource.Rows[j]["TypeID"].ToString() == dt_UserProjectSchedule.Columns[i].ColumnName.ToString())
        //        {
        //            if (dt_MustResource.Rows[j]["ResourceID"].ToString() == dt_UserProjectSchedule.Columns[i].ColumnName.ToString())
        //            {
        //                dt_UserProjectSchedule.Columns[i].SetOrdinal(j + 4);
        //            }
        //        }
        //    }
        //}       

        ////打印ＴＡＢＬＥ
        //for (int i = 0; i < dt_UserProjectSchedule.Rows.Count; i++)
        //{
        //    str_table.Append(TABLE_TR_BEGIN);

        //    for (int j = 0; j < dt_UserProjectSchedule.Columns.Count - 1; j++)
        //    {
                
        //        if (dt_UserProjectSchedule.Rows[i][j].ToString().Trim() == "1")
        //        {
        //            str_table.Append(TD_STARTING_BEGIN);
        //            str_table.Append("进行中");
        //            str_table.Append(TD_STARTING_END);
        //        }
        //        else if (dt_UserProjectSchedule.Rows[i][j].ToString().Trim() == "2")
        //        {
        //            str_table.Append(TD_END_BEGIN);
        //            str_table.Append("已结束");
        //            str_table.Append(TD_END_END);
        //        }
        //        else if (dt_UserProjectSchedule.Rows[i][j].ToString().Trim() == "")
        //        {
        //            str_table.Append(TD_UNSTART_BEGIN);
        //            str_table.Append("未开始");
        //            str_table.Append(TD_UNSTART_END);
        //        }
        //        else
        //        {
        //            str_table.Append(TBALE_TD_BEGIN);
        //            str_table.Append(dt_UserProjectSchedule.Rows[i][j].ToString());
        //            str_table.Append(TBALE_TD_END);
        //        }
                
        //    }
        //    str_table.Append(TBALE_TD_END);
        //}

        //str_table.Append(TABLE_END);
        //lab_table.Text = str_table.ToString();

    }

    protected void btnSearch_Click(object sender, EventArgs e)
    {
        string search = GetSearch();
        BinderPager(search);
        BinderGV(search, 1);
    }
    protected void AspNetPager1_PageChanged(object sender, EventArgs e)
    {
        string search = GetSearch();
        BinderPager(search);
        BinderGV(search, 1);
    }
    protected void btnExport_Click(object sender, EventArgs e)
    {
        //ArrayList list = new ArrayList();
        //DataTable dt = (DataTable)ViewState["dt"];
        //for (int i = 0; i < dt.Columns.Count; i++)
        //{
        //    if (dt.Columns[i].ColumnName == "ClassName")
        //    {
        //        dt.Columns[i].ColumnName = "班级名称";
        //        dt.Columns[i].SetOrdinal(0);
        //    }
        //    else if (dt.Columns[i].ColumnName == "UserName")
        //    {
        //        dt.Columns[i].ColumnName = "帐户";
        //        dt.Columns[i].SetOrdinal(1);
        //    }
        //    else if (dt.Columns[i].ColumnName == "RealName")
        //    {
        //        dt.Columns[i].ColumnName = "真实姓名";
        //        dt.Columns[i].SetOrdinal(2);
        //    }
        //    else if (dt.Columns[i].ColumnName == "ResourceName")
        //    {
        //        dt.Columns[i].ColumnName = "资源名称";
        //        dt.Columns[i].SetOrdinal(3);
        //    }
        //    else
        //    {
        //        list.Add(dt.Columns[i].ColumnName);

        //    }
        //}
        //for (int i = 0; i < list.Count; i++)
        //{
        //    dt.Columns.Remove(list[i].ToString());
        //}
        //Excel objExcel = new Excel();
        //objExcel.ToExcel(dt, this.Page, "培训进度统计", "培训进度统计信息", "ProjectInfo");
    }
}
